﻿using AutoMapper;
using WeatherHistory.Api.CommandsQueries.Mapping;
using WeatherHistory.Data.Entities;

namespace WeatherHistory.Api.CommandsQueries.Queries.Regions.GetOne;

public class GetOneRegionsQueryResponse : IMapWith<Region>
{
    public long Id { get; set; }
    public long AccountId { get; set; }
    public string Name { get; set; } = null!;
    public string ParentRegion { get; set; } = null!;
    public double Latitude { get; set; }
    public double Longitude { get; set; }
    public long? RegionType { get; set; }

    public void Mapping(Profile profile)
    {
        profile.CreateMap<Region, GetOneRegionsQueryResponse>()
            .ForMember(dest => dest.Id,
                opt => opt.MapFrom(src => src.Id))
            .ForMember(dest => dest.Name,
                opt => opt.MapFrom(src => src.Name))
            .ForMember(dest => dest.ParentRegion,
                opt => opt.MapFrom(src => src.ParentRegion.Name))
            .ForMember(dest => dest.Latitude,
                opt => opt.MapFrom(src => src.Latitude))
            .ForMember(dest => dest.Longitude,
                opt => opt.MapFrom(src => src.Longitude))
            .ForMember(dest => dest.AccountId,
                opt => opt.MapFrom(src => src.CreatedById))
            .ForMember(dest => dest.RegionType,
                opt => opt.MapFrom(src => src.RegionTypeId));
    }
}